package cn.yunhe.controller;

import cn.yunhe.entity.Topic;
import cn.yunhe.service.ItopicService;
import cn.yunhe.service.implService.TopicService;
import cn.yunhe.util.JsonUtil;
import cn.yunhe.util.Paganation;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "GetAllTopicServlet",urlPatterns = "/GetAllTopicServlet")
public class GetAllTopicServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String  pageNoStr=request.getParameter("pageNo");
        int pageNo=1;
        if(pageNoStr!=null){
            pageNo=Integer.parseInt(pageNoStr);
        }
        Topic topic=new Topic();
        Paganation<Topic> paganation=new Paganation<Topic>();

        Paganation paganation1=new Paganation();
        paganation1.setPageNo(pageNo);

        ItopicService topicService=new TopicService();
        paganation=topicService.getAllTopic(topic,paganation1);

        JsonUtil.getJson(response,paganation);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doPost(request,response);
    }
}
